package org.example.sleep;

import java.util.concurrent.TimeUnit;

/**
 * @Title : SleepThread
 * @Description: :
 * @author: libo@juzishuke.com
 * @date: 2023/10/24 15:14
 * @Version:1.0
 */
public class SleepThread {

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            long startTime = System.currentTimeMillis();
            sleep(2_000L);
            long endTime = System.currentTimeMillis();
            System.out.println(String.format("Total spend %d ms", (endTime - startTime)));
        }).start();
        long startTime = System.currentTimeMillis();
//        sleep(3_000L);
        TimeUnit.MILLISECONDS.sleep(2_000L);
        long endTime = System.currentTimeMillis();
        System.out.println(String.format("Main thread total spend %d ms", (endTime - startTime)));

    }

    private static void sleep(long ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
